home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / DESK / CORE / Desk / h_doc / DynamArea < prev    next >
Text File  |  1996-07-30  |  4KB  |  135 lines

  1. /*
  2.     ####             #    #     # #
  3.     #   #            #    #       #          The FreeWare C library for
  4.     #   #  ##   ###  #  # #     # ###             RISC OS machines
  5.     #   # #  # #     # #  #     # #  #   ___________________________________
  6.     #   # ####  ###  ##   #     # #  #
  7.     #   # #        # # #  #     # #  #    Please refer to the accompanying
  8.     ####   ### ####  #  # ##### # ###    documentation for conditions of use
  9.     ________________________________________________________________________
  10.  
  11.     File:    DynamArea.h
  12.     Author:  Copyright © 1996 Julian Smith.
  13.     Version: 1.00 
  14.     Purpose: Simple management of dynamic areas.
  15.     History: 1.00 (12 Jul 1996)
  16.  
  17.  */
  18.  
  19.  
  20. /*
  21. These functions allow dynamic areas to be easily created, resized and
  22. deleted.
  23.  
  24. The main reason for this library is that the SWI provided by RISC OS for
  25. changing the size of a DA (OS_ChangeDynamicArea) is rather tricky to
  26. use, for two reasons:
  27.  
  28. 1    It expects the change in the size of the dynamic area, rather
  29.     than an absolute size.
  30. 2    This change is relative to the actual size of the DA, rather
  31.     than the size last requested (DAs are rounded up to a multiple
  32.     of a page-size).
  33.  
  34. Also, this library keeps a list of created DAs, and can delete them all
  35. when the program finishes.
  36.  
  37. No facility is provided for heap-management within individual dynamic
  38. areas.
  39.  */
  40.  
  41. #ifndef __Desk_DynamArea_h
  42. #define __Desk_DynamArea_h
  43.  
  44.  
  45. typedef struct Desk_DynamicArea_block    {
  46.     int                id;        /* Used with OS_ChangeDynamicArea SWI etc    */
  47.     void*                data;        /* Pointer to start of dynamic area        */
  48.     size_t                datasize;    /* Last size passed to Desk_DynamicArea_SetSize    */
  49.     size_t                size;        /* Actual size of the dynamic area - probably     */
  50.                             /* 'datasize' rounded up to multiple of machine    */
  51.                             /* page-size.                    */
  52.     struct Desk_DynamicArea_block*    previous;    /* Maintains single-linked list of DAs.        */
  53.     }
  54.     Desk_DynamicArea_block;
  55. /*
  56. Information the Desk_DynamicArea library uses to keep track of all its
  57. dynamic areas.
  58.  
  59. Do /not/ use the fields directly - use only the functions/macros provided.
  60.  */
  61.  
  62.  
  63. void    Desk_DynamicArea_Create( Desk_DynamicArea_block* da, size_t maxsize, const char* name);
  64. /*
  65. Creates a dynamic area for use with Desk_DynamicArea_* calls.
  66.  
  67. da        Pointer to a Desk_DynamicArea_block that must exist for the life of
  68.         the dynamic area.
  69. maxsize        Maximum size the dynamic area will ever be. -1 means the amount
  70.         of RAM in the machine.
  71. name        Name of the dynamic area in the Tasks Manager's window.
  72.  */
  73.  
  74.  
  75. void    Desk_DynamicArea_Delete( Desk_DynamicArea_block* da);
  76. /*
  77. Completely removes the specified dynamic area.
  78.  
  79. da        Pointer to Desk_DynamicArea_block for the dynamic area
  80.         to delete.
  81.  */
  82.  
  83.  
  84. void    Desk_DynamicArea_DeleteAll( void);
  85. /*
  86. This deleted all the dynamic areas created with Desk_DynamicArea_Create.
  87. It is called automatically when the program finishes, using atexit().
  88.  
  89. Note that module builds /don't/ use atexit() in this way, because
  90. atexit() doesn't seem to work reliably in modules. You should therefore
  91. call Desk_DynamicArea_DeleteAll from a modules finalisation code.
  92.  */
  93.  
  94.  
  95. void*    Desk_DynamicArea_SetSize( Desk_DynamicArea_block* da, size_t size);
  96. /*
  97. Makes the specified dynamic area contain at least 'size' bytes. Any
  98. existing data is preserved, up to whatever is the minimum of the the old
  99. and new sizes (ie it behaves like realloc).
  100.  
  101. Returns a pointer to the data.
  102.  
  103. da        Pointer to Desk_DynamicArea_block for the dynamic area
  104.         to set size of.
  105. size        New size of dynamic area.
  106.  */
  107.  
  108.  
  109.  
  110. #define    Desk_DynamicArea_GetSize( da)        ( (da)->size)
  111. /*
  112. size_t    Desk_DynamicArea_GetSize( Desk_DynamicArea_block* da);
  113.  
  114. Returns the actual size of the DA.
  115.  */
  116.  
  117. #define    Desk_DynamicArea_GetDataSize( da)    ( (da)->datasize)
  118. /*
  119. size_t    Desk_DynamicArea_GetDataSize( Desk_DynamicArea_block* da);
  120.  
  121. Returns the last-requested size of the DA (ie the size past to the last
  122. succesfull call to Desk_DynamicArea_SetSize).
  123.  */
  124.  
  125.  
  126. #define    Desk_DynamicArea_GetData( da)        ( (da)->data)
  127. /*
  128. void*    Desk_DynamicArea_GetData( Desk_DynamicArea_block* da);
  129.  
  130. Returns a (void*) to the DA data.
  131.  */
  132.  
  133.  
  134. #endif
  135.